// 
//  htmlparser.js
//  firefox
//  
//  Created by Zak on 2008-07-14.
//  Copyright 2008 Ant.com. All rights reserved.
// 

function AntHtmlParser() {};

AntHtmlParser.prototype = 
{
    parsers: [new AntParserYoutube, new AntParserGeneric],

	/**
	 * Called when a new page is show, begin the treatement
	 * @param currentDoc    The current document
 	 * @param rootDoc       The root document (in case of a frame)
	 */
	onShowPage: function (currentDoc, rootDoc)
	{
		var browser = AntLib.getMainWindow().getBrowser();
		var currentBrowser = browser.getBrowserForDocument(rootDoc);
		var selectedDoc = browser.selectedBrowser.contentDocument;

		if (AntPrefs.isExpertMode() && !AntPrefs.isSiteEnabled(rootDoc.location))
			return;
		this.grab(currentDoc, rootDoc);
	},

    /**
     * Try to grab a link in the DOM of the page, using regular regex add specific downloaders
     * @param doc           The DOM to look in
     */
    grab: function (currentDoc, rootDoc)
    {
        for (var i = 0; i < this.parsers.length; i++)
        {
            var parser = this.parsers[i];
            var arr = null;

			parser.setCurrentDocument(currentDoc);
	        arr = parser.getFlvArray();
			if (arr && arr.length)
			{
			    for (var y = 0; y < arr.length; y++)
				{
				    arr[y].name = rootDoc.title;
				    arr[y].doc = rootDoc;
					AntGrabber.foundFlvLink(arr[y]);
				}
			}
        }
    },
};

